<!DOCTYPE html>
{% load i18n %}
<html lang="zh-CN">
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <meta http-equiv="X-UA-Compatible" content="IE=edge">
        <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no">
        <link rel="shortcut icon" type="image/png" href="/static/favicon.ico"/>
        <link rel="apple-touch-icon" href="/static/apple-touch-icon.png">
        {% include '../show/link.html' %}
        <script src="/static/lib/art-template/web-ie-compatible/es5-shim.min.js"></script>
        <script src="/static/lib/art-template/web-ie-compatible/es5-sham.min.js"></script>
        <script src="/static/lib/art-template/web-ie-compatible/json3.min.js"></script>
        <script src="/static/lib/art-template/template-web.js"></script>

        <title>{% trans '财务记录' %}</title>

        <style>
            .main_right {
                background-color:#fff;
            }

            .main_body {
                min-height: 700px;
            }

            .finance_btn {
                cursor: pointer;
                line-height: 1.42857143;
                color: #0e75ee;
                background:none;
                text-decoration: none;
            }
        </style>

        <script>
            $(document).ready(function() {
                $("#finance").addClass("active");
                //init_finance({})
                get_finance()
            })

            function get_finance() {
                // var userid = $("#userid").val();
                //console.log("get finance")
                $.post("{% url 'get_finance'%}",
                {},
                function(obj) {
                    // console.log("balances" + JSON.stringify(obj))
                    for (var i = 0; i < obj.length; i++) {
                        info = obj[i]
                        info.status1 = get_status(info.type, info.status)
                        info.type_trans = get_type(info.type)
                        info.type1 = get_type(info.type)
                        info.create_time = date_format_iso(info.create_time)
                    }

                    var data = {
                        jsonobj: obj,
                        g_coin_info: g_coin_info,
                    }
                    var html = template('temp_finance', data);
                    document.getElementById('show_finance').innerHTML = html;
                    //init_inlink_svg()
                    init_balances_collapse()
                });
            }

            function init_balances_collapse() {
                // 开启
                $('.balance_detail_listen').on('show.bs.collapse', function () {
                    var detail_uuid =  $(this).attr('id');
                    //console.log("base" + detail_uuid)
                    var uuid = detail_uuid.substring(7)
                    var type1 =uuid.substring(0,2)
                    var uuid =uuid.substring(3)
                    //console.log("=== type1:" + type1 + " uuid " + uuid + " base" + detail_uuid)
                    show_finance_detail(type1, uuid)
                })
            }

            function get_status(type1, status1) {
                var FINANCE_STATUS_NONE = 0
                var FINANCE_STATUS_APPLY = 1
                var FINANCE_STATUS_FINISH = 2
                var FINANCE_STATUS_ERROR = 3
                if (type1 == 21) {
                    if (status1 == FINANCE_STATUS_FINISH) {
                        return "{% trans '成功' %}"
                    }
                    if (status1 == FINANCE_STATUS_ERROR) {
                        return "{% trans '失败' %}"
                    }
                    if (status1 == FINANCE_STATUS_APPLY) {
                        return "{% trans '等待确认数' %}"
                    }
                    if (status1 == FINANCE_STATUS_NONE) {
                        return ""
                    }
                } else if (type1 == 22) {
                    if (status1 == FINANCE_STATUS_FINISH) {
                        return "{% trans '成功' %}"
                    }
                    if (status1 == FINANCE_STATUS_ERROR) {
                        return "{% trans '失败' %}"
                    }
                    if (status1 == FINANCE_STATUS_APPLY) {
                        return "{% trans '申请中' %}"
                    }
                    if (status1 == FINANCE_STATUS_NONE) {
                        return ""
                    }
                } else if (type1 == 26) {
                    return "{% trans '成功' %}"
                }
            }

            function get_type(type1) {
                //var DEPOSIT_21  # 充值得到
                //var WITHDRAW_22  # 提现 = - (金额，包括手续费,包括旷工手续费) = (用户得到 + 矿工消耗 + WITHDRAW_FEE)
                if (type1 == 21) {
                    return '<span style="color:#0e75ee">{% trans '充值' %}</span>'
                } else if (type1 == 22) {
                    return '<span class="red">{% trans '提现' %}</span>'
                } else if (type1 == 26) {
                    return '<span class="red"><b>{% trans '系统送币' %}</b></span>'
                }
            }

            // 显示内容
            function show_finance_detail(type1, uuid) {
                if (type1 == 21) {
                    get_deposites(type1, uuid)
                } else if (type1 == 22) {
                    get_withdrawes(type1, uuid)
                }
            }

            function get_deposites(type1, uuid) {
                // var userid = $("#userid").val();
                //console.log("get deposites")
                $.post("/btc/get_deposites",
                {uuid:uuid},
                function(data) {
                    //console.log("deposites" + JSON.stringify(data))
                    var data = {
                        info: data,
                    }

                    html = template('temp_deposit_detail', data);
                    var temp_key = "#detail_" + type1 + "_" + uuid
                    $(temp_key).html(html)
                });
            }

            function get_withdrawes(type1, uuid) {
                //console.log("get withdrawes" + uuid)
                $.post("/btc/get_withdrawes",
                {uuid:uuid},
                function(data) {
                    var data = {
                        info: data,
                    }

                    html = template('temp_withdraw_detail', data);
                    var temp_key = "#detail_" + type1 + "_" + uuid
                    $(temp_key).html(html)
                });
            }
        </script>
    </head>

    {% include 'show/common_define.html' %}
    <script src="/static/site/common_func.js"></script>
    <body>
        {% include '../show/top_bar.html' %}
        <div class="main_body">
            <br>
            <div class="container">
                {% include '../userinfo/sider.html' %}
                <div id="" class="col-md-10 main_right">

                    <div class="panel">
                        <div class="panel-heading">
                            <!---div class="panel-heading-title title">
                                <a href="#"> {% trans '充值记录' %} </a>
                                <a href="#"> {% trans '提现记录' %} </a>
                                <a href="#"> {% trans '其他记录' %} </a>
                            </div-->
                        </div>
                        <div class="panel-body">
                            <div id="show_finance"> </div>
                        </div>
                    </div>

                </div>
            </div>
        </div>
        {% include '../show/footer.html' %}
    </body>
</html>

<script id="temp_finance" type="text/html">
    <div class="panel-group" id="accordion2">
    <table id="tbl_finance" class="table table-hover" cellspacing="0" width="100%">
        <thead>
            <tr>
                <th width="20%" >{% trans '时间' %}</th>
                <th width="15%" >{% trans '币种' %}</th>
                <th width="15%" >{% trans '类型' %}</th>
                <th width="15%" >{% trans '数量' %}</th>
                <th width="15%" >{% trans '状态' %}</th>
                <th width="20%" >{% trans '操作' %}</th>
            </tr>
        </thead>
        <tbody>
            <% for(i = 0; i < jsonobj.length; i ++ ) { %>
                <% var info = jsonobj[i] %>
                <% var coin_type = info.coin_type.toUpperCase() %>
                <% var type = info.type_trans %>
                <% var status1 = info.status1 %>
                <% var status = info.status %>
                <% var url = "detail_" + info.type + "_" + info.uuid %>

                <tr >
                    <td><%=info.create_time%></td>
                    <td><%=coin_type%></td>
                    <td><%-type%></td>
                    <td><%=info.amount%></td>
                    <td><%=status1%></td>
                    <td>
                        <% if (status == 2 || (status == 1 && info.type == 21)) { %>
                            <a data-toggle="collapse" class="finance_btn dropdown-toggle" data-parent="#accordion2" href="#<%=url%>">{% trans '详情'%}<b class="caret"></b></a>
                        <% } %>
                    </td>
                </tr>
                <tr style="padding:0px;margin:0px;border:0px;" >
                    <td colspan=6 style="padding:0px;margin:0px;border:0px;">
                        <div id="<%=url%>" class="panel-collapse collapse balance_detail_listen">
                        </div>
                    </td>
                </tr>
            <% } %>
        </tbody>
    </table>
    </div>
</script>

<script id="temp_deposit_detail" type="text/html">
    <% var coin_type = info.coin_type %>
    <% var create_time = date_format_iso(info.create_time) %>
    <% var confirm_time = "" %>
    <% if (info.confirm_time) { %>
        <% confirm_time = $imports.dateFormat(info.confirm_time) %>
    <% } %>
    <% var amount = info.amount * 1 %>
    <% var confirmations = info.confirmations%>
    <% var status1 = info.status %>
    <% if(coin_type == 'btc') { %>
        <% var confirm_url = "https://blockchain.info/zh-cn/tx/" + info.txid %>
    <% } else if (coin_type == 'ltc') { %>
        <% var confirm_url = "https://block.cc/q/" + info.txid %>
    <% } else { %>
        <% var confirm_url = "https://etherscan.io/tx/" + info.txid %>
    <% } %>
    <% status = $imports.gettext('等待确认数')%>
    <% if (status1 == 0) { %>
        <% status = $imports.gettext('等待确认数')%>
    <% } else if(status1 == 1) { %>
        <% status = $imports.gettext('充值成功') %>
    <% } else if(status1 == 2) { %>
        <% status = $imports.gettext('充值失败') %>
    <% } %>
    <div class="panel-body" style="background-color:#F1F1F1F1" >
        <table class="collapse_detail col-sm-12" role="alert">
            <tr>
                <td ><span class="gray"> {% trans '申请时间' %}</span>: </td><td><span><%=create_time%></span></td>
            </tr>
            <tr>
                <td ><span class="gray">{% trans '充值地址' %}</span>: </td><td><span><%=info.address%></span></td>
            </tr>
            <tr>
                <td ><span class="gray">{% trans '区块链交易id' %}</span>: </td><td><span><a href="<%=confirm_url%>" target="_blank"><%=info.txid%></a></span></td>
            </tr>
        </table>
    </div>
</script>

<script id="temp_withdraw_detail" type="text/html">
    <% var coin_type = info.coin_type %>
    <% var amount = info.amount * 1 %>
    <% var fee = info.fee * 1 %>
    <% var address = info.address %>
    <% var status1 = info.status %>
    <% if(coin_type == 'btc') { %>
        <% var confirm_url = "https://blockchain.info/zh-cn/tx/" + info.txid %>
    <% } else if (coin_type == 'ltc') { %>
        <% var confirm_url = "https://block.cc/q/" + info.txid %>
    <% } else { %>
        <% var confirm_url = "https://etherscan.io/tx/" + info.txid %>
    <% } %>
    <% var errmsg = info.errmsg %>
    <% var create_time = date_format_iso(info.create_time) %>
    <% status = "提现成功" %>
    <% if (status1 == 0) { %>
        <% status = "提现中" %>
    <% } %>
    <% if (status1 == 1) { %>
        <% status = "正在处理" %>
    <% } %>
    <% if (status1 == 2) { %>
        <% status = "正在处理" %>
    <% } %>
    <% if (status1 == 3) { %>
        <% status = "正在处理" %>
    <% } %>
    <% if (status1 == 5) { %>
        <% status = "提现失败，已经回滚" %>
    <% } %>
    <div class="panel-body" style="background-color:#F1F1F1F1" >
        <table class=" col-sm-12" role="alert" ">
            <tr>
                <td class="f-left"><span>{% trans '申请时间' %}</span>:<span><%=create_time%></span></td>
                <td class="f-left"><span>{% trans '提现地址' %}</span>:<span><%=address%></span></td>
            </tr>
            <tr>
                <td class="f-left"><span>{% trans '手续费' %}</span>:<span><%=fee%></span></td>
                <% if (status1 == 5) { %>
                    <td class="f-left">{% trans '提现失败，已经撤销:' %}</td>
                <% } else { %>
                    <td class="f-left"><span>{% trans '区块链交易id' %}</span>:<span><a href="<%=confirm_url%>" target="_blank"><%=info.txid%></a></span></td>
                <% } %>
            </tr>
        </table>
    </div>
</script>
